
#include "zen_game_sprite.h"
#include "zen_game_activity.h"
#include <array>

namespace Zen
{
	namespace Game
	{
		static std::shared_ptr<Zen::Graphics::Buffer> CreateSpritePolygonBuffer()
		{
			auto buffer = Zen::Game::Activity::Only()->GetGraphicsEngine()->GenerateBuffer();
			Point2 data[] = { { 0, 0 }, { 1, 0 }, { 0, 1 }, { 1, 1 } };
			buffer->Initialize(sizeof(Point2) * std::size(data), data);
			return buffer;
		}

		Sprite::Sprite()
		{
			static auto buffer = CreateSpritePolygonBuffer();
			this->SetVertexCount(4);
			this->SetPolygonBuffer(buffer, 2);
			this->SetDrawMode(Zen::Graphics::EDrawMode::TriangleStrip);
		}
		void Sprite::OnTextureChange() {}
		void Sprite::Flush()
		{
			if (mTextureFrame) mTextureCoordBuffer = mTextureFrame->GetDefaultCoordBuffer();
		}
		void Sprite::OnReady(std::shared_ptr<RenderStack> stack, float interval)
		{
			Flush();
			FigureTexture::OnReady(stack, interval);
		}
	} // namespace Game
} // namespace Zen
